<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:cu="http://apache.org/cocoon/counit" 
  version="1.0">

  <!-- 
    Include the expected output in the document.  
    Of course this is only necessary if the @expect attrib is used (which points to 
    an external XML file) and not the expect nodeset, which already contains the expected output.
  
  Authors: Jan Willem Boer <janwillem@jwenr.nl>
  -->
  <xsl:template match="cu:testcase">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:if test="@expect">
        <xsl:if test="cu:expect">
          <xsl:message terminate="yes">using cu:testcase/@expect and cu:testcase/cu:expect
            simultaneously is not allowed.</xsl:message>
        </xsl:if>
        <cu:expect>
          <xsl:copy-of
            select="document(concat(parent::node()/@base, parent::node()/@testsuite-dir, @expect))"
          />
        </cu:expect>
      </xsl:if>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- copy everything else -->
  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
